package InterfaceDemo;



public class Printer extends NetworkDevice implements Device, UsbDevice {
    private String model;

    public Printer(String model) {
        this.model = model;
    }


    @Override
    public void powerOn() {
        System.out.println("【" + model + "打印机】开机，指示灯变绿，准备就绪");
    }

    @Override
    public void powerOff() {
        System.out.println("【" + model + "打印机】关机，保存打印任务，指示灯熄灭");
    }

    @Override
    public void repair() {
        System.out.println("【" + model + "打印机】报修：常见问题-卡纸/缺墨/网络断开");
    }


    @Override
    public void connectNetwork(ConnectionCallback callback) {
        try {

            Thread.sleep(500);
            System.out.println("【" + model + "打印机】正在连接WiFi...");
            Thread.sleep(500);

            callback.onSuccess(model, "网络");
        } catch (InterruptedException e) {
            // 连接失败，触发回调
            callback.onFailure(model, "网络", "连接超时（模拟异常）");
        }
    }


    @Override
    public void connectUsb(ConnectionCallback callback) {
        try {

            Thread.sleep(300);
            System.out.println("【" + model + "打印机】正在插入USB接口...");
            Thread.sleep(300);

            callback.onSuccess(model, "USB");
        } catch (InterruptedException e) {

            callback.onFailure(model, "USB", "接口接触不良（模拟异常）");
        }
    }


    public String getModel() {
        return model;
    }
}